<?php $this->fetch('public/head') ?>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">信息列表</li>
    </ul>
    <div class="layui-tab-content">
        <div id="ss" class="layui-form layui-form-pane">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="reward" lay-filter="query" class="query">
                        <?php foreach($reward as $k=>$v): ?>
                            <option value="<?php echo $k ?>" <?php if(input('nid')==$k){echo 'selected="selected"';} ?>><?php echo $v ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select name="complete_type" lay-filter="query" class="query">
                        <option value="">全部</option>
                        <?php foreach($complete_type as $k=>$v): ?>
                            <option value="<?php echo $k ?>" <?php if(input('nid')==$k){echo 'selected="selected"';} ?>><?php echo $v ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" value="<?php echo input('title') ?>" placeholder="请输入关键词" class="layui-input query">
                </div>
            </div>
        </div>
        <hr>

        <div class="layui-tab-item layui-show">
            <table id="dataList" lay-filter="dataList" class="layui-hide"></table>
        </div>
    </div>
</div>
<?php $this->fetch('public/script') ?>

<script>
    layui.use(['table'], function(){
        var table = layui.table
            ,form = layui.form;

        getLists();
        form.on('select(query)', function(data){
            $(data.elem).trigger('change',data.elem); //此处可让select支持change事件，trigger方法触发被选元素的指定事件类型。
        });
        //改变查询条件后重新获取列表数据
        $('.query').change(function () {
            getLists();
        });

        function getLists() {
            let params = HS.getParams('.query');
            //数据表格
            let load_table = layer.load(0, {time: 30000});
            table.render({
                elem: '#dataList'
                , height:$(window).height()-155
                , url: '<?php echo url('getLists') ?>' //数据接口
                , method: 'post'
                , where: params
                , response: {
                    countName: 'total' //数据总数的字段名称，默认：count
                }
                , page: {
                    limit: 20
                    , limits: [20, 30, 50, 100]
                    , groups: 5
                    , layout: ['prev', 'page', 'next', 'limit', 'refresh', 'skip', 'count']
                } //开启分页
                , defaultToolbar: ['filter']    //, 'print', 'exports'
                , cols: [[ //表头
                    {field: 'id', title: 'ID', width: 50, event: 'detail'}
                    , {field: 'title', title: '标题',  event: 'detail'}
                    , {field: 'user_name', title: '提议人'}
                    , {field: 'department', title: '部门'}
                    , {field: 'question_classfy', title: '问题类型'}
                    , {field: 'finish_time', title: '完成时间', event: 'detail'}
                    , {title: '详情', templet: function (d) {
                        var html = '';
                        if(d.reward>0){
                            html= '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="log">发放记录</a></div>'
                        }else{
                            html= '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reward">发放红包</a>'
                        }
                            return '<div><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">详情</a>'+
                                '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="score">查看评分</a>'+html

                        }, event: 'detail'}
                ]]
                , text: {none: '暂无相关数据'}
                , done: function (res, curr, count) {
                    layer.close(load_table);
                }
            })
        }
        //监听工具条
        table.on('tool(dataList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            //var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'edit'){ //编辑
                layer.open({
                    type:2,
                    title:'详情',
                    area:['80%','80%'],
                    content:HS.U('/admin/jdz/detail',{id:data.id})
                })
            }
            if(layEvent=='score'){
                layer.open({
                    type: 2,
                    title:'评分列表' ,
                    area:['80%','80%'],
                    content:HS.U('/admin/jdz/score',{id:data.id})
                })
            }
            if(layEvent=='reward'){
                layer.open({
                    type: 2,
                    title:'评分列表' ,
                    area:['80%','80%'],
                    content:HS.U('/admin/jdz/reward_touser',{id:data.id})
                })
            }
            if(layEvent=='log'){
                layer.open({
                    type: 2,
                    title:'发放记录' ,
                    area:['80%','80%'],
                    content:HS.U('/admin/jdz/log',{id:data.id})
                })
            }
        });
        //显示/隐藏、置顶操作
    });
</script>